package weaver.interfaces.xfjt.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.jobs.xfjt.duss.utils.XfjtUtil;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-10-07
 * @Description: 周期督查发起流程归档创建周期督查反馈流程
 * @ModifyLog:
 **/
public class WeaKeyProjectCreateAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String currentDate = DateUtil.getCurrentDate();
        writeLog(">>>>WeaCycleGovernCreateAction>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            writeLog(">>>>>>WeKeyProjectsCronJob>>>>currentDate" + currentDate);
            rs.executeQuery("select * from uf_zdgcdc where dczt=0 and lcck=?", requestid);
            String[] columnName = rs.getColumnName();
            if (rs.next()) {
                Map<String, String> requestMainMap = new HashMap<>();
                //数据id
                String dataid = Util.null2String(rs.getString("id"));
                String jsksrq = Util.null2String(rs.getString("jsksrq"));
                int compDateVal = DateUtil.compDate(currentDate, jsksrq);
                if (compDateVal == 0) {
                    //督查重复模式:0-按天重复;1-按周重复;2-按月重复
                    String dczfms = Util.null2String(rs.getString("dczfms"));
                    //每次反馈期限（天）
                    int mcfkqxt = Util.getIntValue(rs.getString("mcfkqxt"));
                    String xywcfkrq = DateUtil.addDate(DateUtil.addDate(currentDate, mcfkqxt), -1);
                    String strs = XfjtUtil.getFieldName("-105");
                    for (String column : columnName) {
                        String columnValue = Util.null2String(rs.getString(column));
                        if (!"".equals(columnValue) && strs.contains(column)) {
                            requestMainMap.put(column, columnValue);
                        }
                    }
                    requestMainMap.put("fkfqrq", currentDate);
                    requestMainMap.put("sjid", dataid);
                    requestMainMap.put("dcnr", dataid);
                    requestMainMap.put("gllc", requestid);
                    requestMainMap.put("xywcfkrq", xywcfkrq);
                    switch (dczfms) {
                        case "0":
                            XfjtUtil.runProjectRntervalDay(currentDate, requestMainMap, dataid);
                            break;
                        case "1":
                            XfjtUtil.runProjectRntervalWeek(currentDate, requestMainMap, dataid);
                            break;
                        case "2":
                            XfjtUtil.runProjectRntervalMonth(currentDate, requestMainMap, dataid);
                            break;
                        default:
                    }
                }
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常！");
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
